<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>Markers with InfoWindow</title>
    <style type="text/css">
      html, body, #map {
        width: 100%;
        height: 100%;
        margin: 0;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script type="text/javascript" src="//webapi.amap.com/maps?v=2.0&key=810add537066b34a513613b32a60ffd1"></script>
    <script>
      var map = new AMap.Map('map', {
        zoom: 4,
        center: [108, 34],
        mapStyle: "amap://styles/grey"
      });
      var capitals = [
        {
            "adcode": "110000",
            "name": "北京",
            "center": [116.407394, 39.904211],
            "hashrate": 20
        },
        {
            "adcode": "620800",
            "name": "庆阳",
            "center": [107.648447, 35.733058],
            "hashrate": 100
        },
        {
            "adcode": "150100",
            "name": "呼和浩特",
            "center": [111.670464, 40.81739],
            "hashrate": 50
        },
        {
            "adcode": "310000",
            "name": "上海",
            "center": [121.473662, 31.230372],
            "hashrate": 30
        },
        {
            "adcode": "321300",
            "name": "宿迁",
            "center": [118.272874, 33.962199],
            "hashrate": 40
        },
        {
            "adcode": "320200",
            "name": "无锡",
            "center": [120.310262, 31.488148],
            "hashrate": 20
        },
        {
            "adcode": "810000",
            "name": "香港",
            "center": [114.171203, 22.277468],
            "hashrate": 15
        },
        {
            "adcode": "710000",
            "name": "台北",
            "center": [121.509062, 25.044332],
            "hashrate": 10
        },
        {
            "adcode": "130100",
            "name": "石家庄",
            "center": [114.499796, 38.042786],
            "hashrate": 8
        }
      ];

      capitals.forEach(function(capital) {
        var center = capital.center;
        
        var marker = new AMap.Marker({
          position: center,
          title: capital.name, // 鼠标悬停时显示的城市名称
          icon: new AMap.Icon({
            size: new AMap.Size(20, 32), // 图标尺寸
            image: '//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png', // 图标图片
            imageSize: new AMap.Size(20, 32) // 图标实际显示尺寸
          }),
          offset: new AMap.Pixel(-10, -32), // 调整标记的偏移量，使其位于城市的正上方
          clickable: true
        });
        // 绑定点击事件
        marker.on('click', function() {
          window.parent.postMessage(capital, "*");
        });
        
        // 将标记添加到地图上
        map.add(marker);
      });
    </script>
  </body>
</html>